package com.example.demo_news.controller.admin;

import com.example.demo_news.service.Admin.AdminIndexService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;


@Controller
@PreAuthorize("hasAnyRole('admin')")
public class AdminIndexController {
@Autowired
private AdminIndexService adminIndexService;

      //管理员首页
   @RequestMapping("/adminIndex")
   public String adminIndex(Model model){
       if(adminIndexService.findAll(model)){
        return "/admin/adminIndex";
       }
       else return "/user/index";
   }
   //删除新闻
   @RequestMapping("/deleteNews")
   public String deleteNews(Integer id){
       adminIndexService.deleteNews(id);
       return "admin/adminIndex";
   }
   
}
